<template>
  <div>
    <!-- 跟进记录 -->
    <BreakSpace label="跟进记录" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table"
      height="auto"
      :columns="columns"
      :dataSource="contactList"
      :isPagination='false'
      :isToperInfo='false'
      :isColumnFilter='false'
      :isSelectColumn='false'
      selectionType="single"
      :onColumnsChange="columns => this.columns = columns"
    ></FilterTable>
    <!-- 关爱记录 -->
    <BreakSpace label="关爱记录" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table"
      height="auto"
      :columns="columns2"
      :dataSource="loveList"
      :isPagination='false'
      :isToperInfo='false'
      :isColumnFilter='false'
      :isSelectColumn='false'
      selectionType="single"
      :onColumnsChange="columns2 => this.columns2 = columns2"
    ></FilterTable>
  </div>
</template>

<script>
import {
  queryContactRecord,
  queryOrderRecord,
  queryVisitHsitory,
  queryPlateContactRecordList
} from '@/api/potenCus/customer/potenCusManage';
import { dictionary } from '@/utils/dictMixin';
import { formatDates, formatDuring } from '@/utils/validate';

export default {
  name: 'contactRecord',
  mixins: [dictionary],
  props: {
    type: {
      type: String,
      default: 'show'
    },
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    this.saveData = null;
    return {
      contactList: [],
      columns: this.createTableColumns(),
      loveList: [],
      columns2: this.createTableColumns2(),
      handleType: '',
    };
  },
  created() {
    this.init();
    this.queryContactList()
  },
  methods: {
    init() {
      // 接口需要的记录 ID
      console.log(this.columns,'this.rowData', this.rowData)
      this.customerBusinessId = this.rowData.customerBusinessId;
      this.potentialCustomerId = this.rowData.potentialCustomersId;
      console.log('this.customerBusinessId', this.customerBusinessId)
      if(this.customerBusinessId){
          this.queryVisitList()
      }

      this.columns[9].filterItems = this.createDictList('1516').concat(this.createDictList('7053')).concat(this.createDictList('7021')).concat(this.createDictList('1517'))
    },
    // 跟进记录
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '计划跟进时间',
          dataIndex: 'planActionDate',
          width: 150,
          align: 'center',
          filterType: 'input',
          render: props =>{
            return <span>{ formatDates(props.row.planActionDate) } </span>
          }
        },
        {
          title: '实际跟进时间',
          dataIndex: 'factActionDate',
          width: 150,
          align: 'center',
          filterType: 'input',
          render: props =>{
            return <span>{ formatDates(props.row.factActionDate) } </span>
          }
        },
        {
          title: '是否首次跟进',
          dataIndex: 'timeLabel',
          align: 'center',
          filterType: 'input',
          initialValue: ''
        },
        {
          title: '跟进备注',
          dataIndex: 'taskName',
          align: 'center',
          filterType: 'input',
        },
        {
          title: '跟进方式',
          dataIndex: 'actionModeName',
          align: 'center',
          filterType: 'input',
         /*20191206切换
         dataIndex: 'planActionMode',
          filterType: 'checkbox',
          filterItems: this.createDictList('1516'),
          render: props => {
            return <span>{this.createDictText(props.row.planActionMode, '1516')}</span>;
          } */
        },
        {
          title: '是否逾期',
          dataIndex: 'isOver',
          align: 'center',
          filterType: 'input',
          render: props => {
            return <span>{((new Date(props.row.factActionDate)).getTime()-(new Date(props.row.planActionDate)).getTime() >= 0 ? '是':'否')}</span>;
          }
        },
        {
          title: '逾期时长',
          dataIndex: 'overTime',
          align: 'center',
          width: 200,
          filterType: 'input',
          render: props => {
            return <span>{ new Date(props.row.factActionDate)>new Date(props.row.planActionDate)?'formatDuring(new Date(props.row.factActionDate)-new Date(props.row.planActionDate))':''}</span>;
          }
        },
        {
          title: '是否完成',
          dataIndex: 'icComplete',
          align: 'center',
          filterType: 'input'
        },
        // {
        //   title: '潜客热度',
        //   dataIndex: 'temperature',
        //   align: 'center',
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList('7018'),
        //   render: props => {
        //     return <span>{this.createDictText(props.row.temperature, '7018')}</span>;
        //   }
        // },
        {
          title: '跟进结果',
          dataIndex: 'actionStatus',
          align: 'center',
          filterType: 'checkbox',
          filterItems: this.createDictList('1517'),
          render: props => {
            let planActionName = ''
            // console.log(props.row.actionStatus,"跟进方式",this.columns[9].filterItems)
            this.columns[9].filterItems.forEach(x=>{
              if(x.value == props.row.actionStatus){
                  planActionName = x.text
              }
            })
            return <span>{planActionName}</span>;
            // return <span>{this.createDictText(props.row.actionStatus, '1517')}</span>;
          }
        },
        //20191207新增失效原因、本次根据情形，删除线索热度、预约时间
        {
          title: '失效原因',
          dataIndex: 'resuleReason',
          align: 'center',
          filterType: 'input',
          render: props =>{
            return <span>{this.createDictText(props.row.resuleReason, '7055')}</span>;
          }
        },
        {
          title: '本次根据情形',
          dataIndex: 'scene',
          align: 'center',
          filterType: 'input',
        },
        // {
        //   title: '预约时间',
        //   dataIndex: 'bookingDate',
        //   width: 200,
        //   align: 'center',
        //   filterType: 'input',
        //   render: props =>{
        //     return <span>{ formatDates(props.row.bookingDate) } </span>
        //   }
        // },
        {
          title: '所属顾问',
          dataIndex: 'consultant',
          align: 'center',
          filterType: 'input'
        },
      ];
    },
    // 关爱记录
    createTableColumns2() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '关爱类型',
          dataIndex: 'planCareDate',
          align: 'center',
          filterType: 'input'
        },
        {
          title: '关爱名称',
          dataIndex: 'actualCareDate',
          align: 'center',
          filterType: 'input'
        },
        {
          title: '关爱方式',
          dataIndex: 'careWay',
          align: 'center',
          filterType: 'input'
        },
        {
          title: '关爱人',
          dataIndex: 'overdue',
          align: 'center',
          filterType: 'input'
        },
        {
          title: '整体满意度',
          dataIndex: 'overdueDate',
          align: 'center',
          // render: props =>{
          //   return <span>{ formatDuring(props.row.leaveTime-props.row.arriveDate) } </span>
          // }
        },
        {
          title: '关爱内容',
          dataIndex: 'whetherFinish',
          align: 'center',
          filterType: 'input'
        },
        {
          title: '关爱状态',
          dataIndex: 'employeeId',
          align: 'center',
          filterType: 'input'
        },
        {
          title: '关爱时间',
          dataIndex: 'customerFeedback',
          align: 'center',
          filterType: 'input'
        }
      ];
    },
    async queryVisitList() {
      const res = await queryVisitHsitory(this.customerBusinessId);
      // const res = await queryVisitHsitory(545);
      console.log('查询回访记录', res)
      if (res.resultCode === 200) {
        this.loveList = res.data
      }
    },
    async queryContactList() {
      // const res = await queryContactRecord(this.customerBusinessId);
      const res = await queryPlateContactRecordList(this.potentialCustomerId,this.customerBusinessId)
      // const res = await queryContactRecord(545);
      console.log('查询跟进记录', res.data)
      if (res.resultCode === 200) {
        this.contactList = res.data.actionedDTOList
        // this.gjList[0].timeLabel ='是'
        this.contactList.forEach((item, index)=>{
          console.log(111,item, index)
          if(index == 0){
            item.timeLabel ='是'
          } else{
            item.timeLabel ='否'
          }
        })
      }
    },
  }
};
</script>

<style lang="less" scoped>
</style>

